use arrow::array::{Array, Float64Array};
use std::sync::Arc;

pub struct MatrixOperations;

impl MatrixOperations {
    pub fn matrix_multiply(a: &[f64], b: &[f64], a_rows: usize, a_cols: usize, b_cols: usize) -> Result<Vec<f64>, Box<dyn std::error::Error>> {
        if a_cols != b.len() / b_cols {
            return Err("Matrix dimensions don't match for multiplication".into());
        }
        
        let mut result = vec![0.0; a_rows * b_cols];
        
        for i in 0..a_rows {
            for j in 0..b_cols {
                let mut sum = 0.0;
                for k in 0..a_cols {
                    sum += a[i * a_cols + k] * b[k * b_cols + j];
                }
                result[i * b_cols + j] = sum;
            }
        }
        
        Ok(result)
    }
}

pub struct VectorOperations;

impl VectorOperations {
    pub fn vector_add(a: &[f64], b: &[f64]) -> Result<Vec<f64>, Box<dyn std::error::Error>> {
        if a.len() != b.len() {
            return Err("Vector dimensions don't match for addition".into());
        }
        
        let result = a.iter().zip(b.iter()).map(|(&x, &y)| x + y).collect();
        
        Ok(result)
    }
    
    pub fn vector_dot(a: &[f64], b: &[f64]) -> Result<f64, Box<dyn std::error::Error>> {
        if a.len() != b.len() {
            return Err("Vector dimensions don't match for dot product".into());
        }
        
        let result = a.iter().zip(b.iter()).map(|(&x, &y)| x * y).sum();
        
        Ok(result)
    }
}